function get_cookie(name) {
	 if (document.cookie.length > 0) {
		 var start = name + '=';
		 var offset = document.cookie.indexOf(start);
		 if (offset != -1) {
			offset += start.length;
			var end = document.cookie.indexOf(';',offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		 }
	 }
	 return '';
}

function set_cookie(name, value) {
	var argv = set_cookie.arguments;
	var argl = set_cookie.arguments.length;
	var expire = argl > 2 ? argv[2] : null;
	if (expire == null) {
		var expire = new Date();
		expire.setTime(expire.getTime() + 365 * 24 * 3600);
	}
	document.cookie = name+'='+escape(value)+';path=/;expire='+expire.toGMTString();
}

function load_guestinfo() {
	$("input[name='comment_author']").val(get_cookie('comment_author'));
	$("input[name='comment_email']").val(get_cookie('comment_email'));
	$("input[name='comment_url']").val(get_cookie('comment_url'));
	if (get_cookie('remember') == 1) {
		$('#remember').attr('checked','checked');
	}
}

function reply_comment(id, author) {
	var content = $('#comment_content').val();
	if ( content.indexOf('[re='+id+','+author+']') == -1 ) {
		$('#comment_content').val(content + '[re='+id+','+author+']');
	}
	$("body,html").animate({ scrollTop: $('#comment_content').offset().top }, 500);
	$('#comment_content').focus();
}

function protected_post(postid, field) {
	var password = $(":input[@name='password"+postid+"']").val();
	if (password == '') {
		alert('请输入密码！');
	} else {
		$(":submit[@name='submit"+postid+"']").attr('disabled','disabled');
		var data = 'id='+postid+'&password='+encodeURIComponent(password)+'&field='+field;
		$.post(blog_url + '/do.php?ac=getprotectedpost', data, function (msg) {
			eval("var message = "+msg);
			$(":submit[@name='submit"+postid+"']").removeAttr('disabled');
			if (message.status == 'error') {
				alert(message.data);
			} else if (message.status == 'success') {
				$("#protected_post_"+postid).html(message.data);
			}
		});
	}
}

function resize_img(img) {
	if ( !image_resize_width ) return ;
	if (img.width > image_resize_width) {
		img.style.width = image_resize_width+"px";
		img.style.cursor = 'pointer';
		img.alt = '点击查看原图';
		img.onclick = function() {
			window.open(img.src);
		}
	}
}